﻿<UserControl x:Class="EtlViewer.Viewer.Controls.EventStatsGrid"
             x:ClassModifier="internal"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:utils="clr-namespace:EtlViewer.Viewer.UIUtils"
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="300">
    <UserControl.Resources>
        <utils:ProviderGuidToNameConverter x:Key="ProviderGuidToNameConverter" />
        <utils:EventLevelAggregator x:Key="EventLevelAggregator" />
    </UserControl.Resources>
    <Grid>
        <AdornerDecorator>
            <DataGrid Name="statsGrid"   
                  IsReadOnly="true"
                  AutoGenerateColumns="False" 
                  Style="{StaticResource GridStyle}"
                   MouseDoubleClick="statsGrid_MouseDoubleClick">
                <DataGrid.GroupStyle>
                    <!-- Style for groups at top level. -->
                    <GroupStyle>
                        <GroupStyle.ContainerStyle>
                            <Style TargetType="{x:Type GroupItem}">
                                <Setter Property="Margin" Value="0,0,0,5"/>
                                <Setter Property="Template">
                                    <Setter.Value>
                                        <ControlTemplate TargetType="{x:Type GroupItem}">
                                            <Expander IsExpanded="True" Background="{StaticResource MetroBlueColorBrush}" >
                                                <Expander.Header>
                                                    <DockPanel>
                                                        <TextBlock FontWeight="Bold" Text="{Binding Path=Name, Converter={StaticResource ProviderGuidToNameConverter}}" Margin="5,0,10,0" Width="Auto" Foreground="White"/>
                                                        <TextBlock FontWeight="Bold" Text="{Binding Path=., Converter={StaticResource EventLevelAggregator}}"  Foreground="White"/>                                                        
                                                    </DockPanel>
                                                </Expander.Header>
                                                <Expander.Content>
                                                    <ItemsPresenter />
                                                </Expander.Content>
                                            </Expander>
                                        </ControlTemplate>
                                    </Setter.Value>
                                </Setter>
                            </Style>
                        </GroupStyle.ContainerStyle>
                    </GroupStyle>
                    <!-- Style for groups under the top level. -->
                    <GroupStyle>
                        <GroupStyle.HeaderTemplate>
                            <DataTemplate>
                                <DockPanel Background="LightBlue" Margin="10,0,0,0" >
                                    <TextBlock Text="{Binding Path=Name}" Foreground="Navy" Margin="10,0,0,0" Width="Auto" MinWidth="200"/>
                                    <TextBlock Text="{Binding Path=., Converter={StaticResource EventLevelAggregator}}"   />
                                </DockPanel>
                            </DataTemplate>
                        </GroupStyle.HeaderTemplate>
                    </GroupStyle>
                </DataGrid.GroupStyle>
                <DataGrid.Columns>
                    <DataGridTextColumn Binding="{Binding Path=Id}" Header="Id" MinWidth="30"/>
                    <DataGridTextColumn Binding="{Binding Path=EventName}" Header="Name" MinWidth="200"/>
                    <DataGridTextColumn Binding="{Binding Path=Count}"  Header="Count"/>
                </DataGrid.Columns>
            </DataGrid>
        </AdornerDecorator>
    </Grid>
</UserControl>
